{{include file ="admin/header.tpl"}} {{include file
="admin/navibar.tpl"}} {{include file ="admin/sidebar.tpl"}}

<link rel="stylesheet" type="text/css"
	href="{{$smarty.const.WEBSITE_URL}}/public/assets/lib/jquery-easyui-1.3.4/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css"
	href="{{$smarty.const.WEBSITE_URL}}/public/assets/lib/jquery-easyui-1.3.4/themes/icon.css">
<script type="text/javascript"
	src="{{$smarty.const.WEBSITE_URL}}/public/assets/lib/jquery-easyui-1.3.4/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="{{$smarty.const.WEBSITE_URL}}public/assets/lib/ajaxupload.js"></script>
<style>
#addwin {
	margin: -500px 0 0 -280px;
	/* PLAY THE WITH THE VALUES TO SEE GET THE DESIRED EFFECT */
}
</style>
<script type="text/javascript">


//文件上传组件处理
	$(document).ready(function(){
		$('#query_create_time').datepicker({
		    format: 'yyyy-mm-dd'
		});
	})
		

		jQuery(function () {
			 	var button = jQuery('#selectfile'), interval;//绑定事件
			var load = new AjaxUpload(button, {//绑定AjaxUpload
		    action: "admin/upload/imgfileup",//文件要上传到的处理页面,语言可以PHP,ASP,JSP等
		    type:"POST",//提交方式
		    data:{//还可以提交的值
		        module:"ajaxupload",
		        type:jQuery("#__mstype__").attr("value") 
		    },
		    //选择文件后,是否自动提交.这里可以变成true,自己去看看效果吧.
		    autoSubmit:false,
		    name:'msUploadFile',//提交的名字
		    onChange:function(file,ext){//当选择文件后执行的方法,ext存在文件后续,可以在这里判断文件格式
				$("#file_show").attr("value",file);
		    },
		    onSubmit: function (file, ext) {//提交文件时执行的方法
		    	if(ext && /^(jpg)$/.test(ext)){
					//ext是后缀名
		    		button.value = "upload…";
		    		button.disabled = "disabled";
				}else{	
					alert("只支持 jpg的格式") ;
					return false;
				}
		    },
		    onComplete: function (file, response) {//文件提交完成后可执行的方法
		        button.text('Select');
		        this.enable();
		        var obj = JSON.parse(response)
				import_modelhide();
		    	$.messager.alert('信息',obj.message);
		    	 $('#img').attr('value',obj.filename);
		    }
			});	
				var submit=jQuery('#submit').click(function(){//触发提交的事件.与autoSubmit的设置有关,是否采用
					load.submit();
			});
		});


		function openUpfile(){
			import_modelshow();
		}
		
		function import_modelshow(){ 
			 $('#import_resource_myModal').modal('show');
		}
		function import_modelhide(){
			 $('#import_resource_myModal').modal('hide');
		}



	 function modelshow(){ 
		 $('#addwin').modal('show');
	 }
	 function modelhide(){
		 $('#addwin').modal('hide');
	 }
	 
	 
	function addItemClick(){
		$("#form").form('clear');
		modelshow();
	}
	
	function editItem(){
		var select = getSelect();
		if(select == null ){
			$.messager.alert('错误','请选择要修改的记录!');
			return;
		}
		$("#form").form('clear');
		modelshow();
		$("#form").form('load',select);
	
	}
	function deleteItem(){
		$.messager.confirm('删除确定','确定要删除当前选择的记录!',function(r){
		    if (r){
		    	var select = getSelect();
				if(select == null ){
					$.messager.alert('错误','请选择要删除的记录!');
					return;
				}
				$.ajax({  
		            type: "POST",  
		            dataType: "json",  
		            url: '{{$smarty.const.WEBSITE_URL}}admin/costpoints/deleteSubject',
		            data: { id: select.id },  
		            success: function (data) {  
		             	$('#grid').datagrid('reload'); 
		            },  
		            error: function () {  
		            }  
		        });  
		    }
		});
		
	}

	function subjectAddOrModify(){
		  if(!$('#form').form('validate')){
		        return;
		     }
	    $.post(
				'{{$smarty.const.WEBSITE_URL}}admin/costpoints/saveOrModify',
				$('#form').serialize(),
				function(data){ 
					modelhide();
			    	$('#grid').datagrid('reload'); 
				},
				"json"
	    );
	}
	  
	function win_close(){
		modelhide();
	}


	function getSelect(){
		var select  = $("#grid").datagrid('getSelected');
		if(select == null){
			return null;
		}
		return select;
	}



	function formatOper(val,row,index){
		var datas = $('#userApprovalListgrid').datagrid('getRows');
		if(datas[index].checked == 0){
			return '<button type="button" class="btn btn-primary" onclick="appPass('+index+')">通过</button>'+
			'<button type="button" class="btn btn-primary" onclick="appFail('+index+')">拒绝</button>';
		} 
	}

	function  appPass(index){
		var datas = $('#userApprovalListgrid').datagrid('getRows');
		   $.post(
					'{{$smarty.const.WEBSITE_URL}}admin/costpoints/check',
					{id:datas[index].id,type:0},
					function(data){ 
				    	$('#userApprovalListgrid').datagrid('reload'); 
					},
					"json"
		    );
	}
	function  appFail(index){
		var datas = $('#userApprovalListgrid').datagrid('getRows');
		   $.post('{{$smarty.const.WEBSITE_URL}}admin/costpoints/check',
					{id:datas[index].id,type:1},
					function(data){ 
						$('#userApprovalListgrid').datagrid('reload'); 
					},
					"json"
		    );
	}
	function appState(value,row,index){
		if(value == 0){
			return "未通过"; 
		}else if(value == 1){
			return "已通过";
		}
		  return "其它";
	}

	function checkState(value,row,index){
		if(value == 0){
			return "未审核"; 
		}else if(value == 1){
			return "已审核";
		}
		  return "其它";
	}

	function query(){
		 	var queryParams = $('#userApprovalListgrid').datagrid('options').queryParams;  
		    collData(queryParams); 			         //重新加载datagrid的数据  
		   $("#userApprovalListgrid").datagrid('reload'); 
	}
	   function collData(queryParams) {
	         queryParams.STATUS = $("#STATUS  option:selected").val();
	         queryParams.CHECKED = $("#CHECKED  option:selected").val();
	         queryParams.USERNAME = $('#username').val();
	         queryParams.CREATE_TIME = $('#query_create_time').val();
	         queryParams.APPROVALNAME = $('#approvalname').val();
	    }
	function clearSearch(){
		$('#searchForm').form('clear');
		 $('#userApprovalListgrid').datagrid({ queryParams: {} }); 
		 $('#userApprovalListgrid').datagrid('reload');
	}
</script>

<div class="content">
	<div class="header">
		<div class="stats">
			<p class="stat">
				<!--span class="number"></span-->
			</p>
		</div>
		<h1 class="page-title">积分兑换管理</h1>
	</div>

		<div class="container-fluid">
			<div class="row-fluid">

		<div class="block">
					<a href="#page-menu" class="block-heading" data-toggle="collapse">用户积分兑换申请列表</a>
					<div id="page-menu" class="block-body collapse in">
						<br />
						<form class="form-search" method="post" id="searchForm">
							
							<div class="input-prepend">
								<span class="add-on">申请人:</span> <input class="input-medium"
									type="text" placeholder="申请人" name="username" id="username"
									 style="width: 120px;">
							</div>
							<div class="input-prepend">
								<span class="add-on">审核人:</span>
									<input class="input-medium"
									type="text" placeholder="审核人" name="approvalname" id="approvalname"
									 style="width: 120px;">
							</div>
							<div class="input-prepend">
								<span class="add-on">申请时间:</span>
									<input  
									type="text"  name="create_time" id="query_create_time" style="width:120px"
									  >
							</div>

							<div class="input-prepend">
								<span class="add-on">申请状态:</span>
							</div>
							<select id="STATUS" name="STATUS" style="width:90px" >
								<option value="0">未通过</option>
								<option value="1">通过</option>
							</select>
							<div class="input-prepend">
								<span class="add-on">审核状态:</span>
							</div>
							<select id="CHECKED" name="CHECKED"  style="width:90px">
								<option value="0">未审核</option>
								<option value="1">已审核</option>
							</select>
							<button type="button" onclick="query()" class="btn btn-primary"  >查询</button>
							<button type="button" onclick="clearSearch()" class="btn "  >重置</button>
						</form>
					</div>
				</div>
		<table id="userApprovalListgrid"
				data-options="url:'admin/costpoints/getApprovalpage',fitColumns:true,singleSelect:true"
				class="easyui-datagrid" style="width: auto; height: 350px"
				  iconCls="icons-save" pagination="true"
					rownumbers="true">
				<thead>
					<tr>
					<th data-options="field:'approvalid',hidden:true"></th>
					<th data-options="field:'userid',hidden:true"></th>
						<th data-options="field:'id',width:100,checkbox:true"></th>
						<th data-options="field:'costpoints',width:100">积分数</th>
						<th data-options="field:'card',width:100">申请物卡金额</th>
						<th data-options="field:'unit',width:100">货币单位</th>
						<th data-options="field:'username',width:100">申请人</th>
						<th data-options="field:'state',width:100,formatter:appState">申请状态</th>
						<th data-options="field:'checked',width:100,formatter:checkState">审核状态</th>
						<th data-options="field:'approvalname',width:100">审核人</th>
						<th data-options="field:'desc',width:100">描述</th>
						<th data-options="field:'create_time',width:100">创建时间</th>
						<th data-options="field:'checked_time',width:100">审核时间</th>
						<th
							data-options="field:'_operate',width:230,align:'center',formatter:formatOper">积分操作</th>
					
					</tr>
				</thead>
			</table>

			<div class="form-actions">
				<h3>积分兑换管理,可以修改,删除添加</h3>
			  <button type="button" class="btn btn-primary" onclick="addItemClick()" >添加</button>
			  <button type="button" class="btn btn-info" onclick="editItem()">修改</button>
			  <button type="button" class="btn btn-danger" onclick="deleteItem()" >删除</button>
			</div>
			<table id="grid"
				data-options="url:'admin/costpoints/getpage',fitColumns:true,singleSelect:true"
				class="easyui-datagrid" style="width: auto; height: 350px"
				  iconCls="icons-save" pagination="true"
					rownumbers="true">
				<thead>
					<tr>
						<th data-options="field:'id',width:100,checkbox:true"></th>
						<th data-options="field:'costpoints',width:100">消耗积分数</th>
						<th data-options="field:'card',width:100">兑换的购物卡金额</th>
						<th data-options="field:'unit',width:100">货币单位</th>
						<th data-options="field:'img',width:100">图片地址</th>
						<th data-options="field:'desc',width:100">描述</th>
						<th data-options="field:'create_time',width:100">创建时间</th>
					
					</tr>
				</thead>
			</table>

			<div id="addwin" class="modal hide fade">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h5>消耗兑换配置</h5>
				</div>
				<div class="modal-body">
					<form id="form" method="post" class="form-horizontal">
						<div class="control-group" hidden="true">
							<input type="text" name="id" hidden="true">
						</div>
						<div class="control-group">
							<label class="control-label" for="Text input">消耗积分数:</label>
							<div class="controls">
								<input type="text" class="easyui-validatebox"
									data-options="required:true" id="costpoints" name="costpoints"
									 placeholder="消耗积分数">
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="inputPassword">使用图片:</label>
							<div class="controls">
								<input type="text" class="easyui-validatebox"
									data-options="required:true" id="img" name="img"
									placeholder="添加图片.可以使用上传"></input>
									<input type="button" onclick="openUpfile()" value="上传"></input>
							</div>
						</div>

						<div class="control-group">
							<label class="control-label"  >兑换购物卡金额:</label>
							<div class="controls">
								<input type="text" id="card" name="card"
									placeholder="兑换购物卡金额">
							</div>
						</div>

						<div class="control-group">
							<label class="control-label"  >描述:</label>
							<div class="controls">
								<textarea rows="4"  id="desc" name="desc"></textarea>
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer" id="div_view">
					<button type="button" style="width: 100px;" class="btn btn-primary"
						onclick="subjectAddOrModify()">提交</button>
					<button type="button" onclick="win_close()" style="width: 100px;"
						class="btn">取消</button>

				</div>
			</div>
			
			
			<div></div>


			<div id="import_resource_myModal" class="modal hide fade">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h3>图片上传</h3>
				</div>
				<div class="modal-body">
				  <div class="control-group">
					  </div>
						<table id="uploadedName" class="table table-hover"  > 
							<tr>
							<td align="right"><a>上传文件名:</a></td>
								<td align="right"><input type="text" id="file_show" class="input-style4 textinput-w3"
									readOnly="true" /></td>
							<td align="left"><input type="button" class="btn"
						id="selectfile" value="选择上传文件" /> </td>
							</tr>
			                </table>
				</div>
				  <div class="modal-footer">
			    <a href="#" onclick="import_modelhide();" class="btn">关闭</a>
			    <a  id="submit" class="btn btn-primary">提交</a>
			  </div>
			</div>
			<!--- END 以下内容不需更改，请保证该TPL页内的标签匹配即可 --->
			{{include file="admin/footer.tpl" }}